import Page
from Page import Yomi
from Base.Base import Base
from selenium.webdriver.common.by import By


class YomiDetailsPage(Base):
    """
    语音训练详情页

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.yomi_home_btn = (By.XPATH, Yomi.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.yomi_back_btn = (By.XPATH, Yomi.RESOURCE_ID.format('ivBack'))

        # 添加技能标题
        self.yomi_add_skill_title_text = (By.XPATH, Yomi.RESOURCE_ID.format("tv_title"))

        # 每当标题
        self.yomi_tip_title_text = (By.XPATH, Yomi.RESOURCE_ID.format("tv_say"))

        # 语音按钮
        self.yomi_voice_btn = (By.XPATH, Yomi.RESOURCE_ID.format("rl_mic"))

        # 输入框
        self.yomi_tip_input = (By.XPATH, Yomi.RESOURCE_ID.format("et_voice"))

        # 字数
        self.yomi_number_text = (By.XPATH, Yomi.RESOURCE_ID.format("tv_count"))

        # 执行标题
        self.yomi_carried_out_title_text = (By.XPATH, Yomi.RESOURCE_ID.format("tv_action"))

        # 技能添加
        self.yomi_add_skill_btn = (By.XPATH, Yomi.skills_added.format(""))

        # 保存
        self.yomi_save_btn = (By.XPATH, Yomi.RESOURCE_ID.format("btn_save"))

        # 取消
        self.yomi_cancel_btn = (By.XPATH, Yomi.RESOURCE_ID.format("tv_cancel"))

        # 技能添加边框
        self.skills_added_frame_icon = (By.XPATH, Yomi.skills_added_frame.format(""))

        # 技能添加名称
        self.skills_added_name_text = (By.XPATH, Yomi.skills_added_name.format(""))

        # 技能添加关闭按钮
        self.skills_added_close_icon = (By.XPATH, Yomi.skills_added_close.format(""))

        # 技能添加详细内容
        self.skills_added_control_text = (By.XPATH, Yomi.skills_added_control.format(""))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.yomi_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.yomi_back_btn)

    def get_add_skill_title(self):
        """
        获取yomi添加技能标题

        :return:获取元素
        """
        return self.find_element_o(self.yomi_add_skill_title_text)

    def get_tip_title(self):
        """
        获取yomi每当标题

        :return:获取元素
        """
        return self.find_element_o(self.yomi_tip_title_text)

    def click_voice(self):
        """
        点击语音按钮

        :return:None
        """
        self.click_element(self.yomi_voice_btn)

    def input_tip(self, index="早上好"):
        """
         输入内容

        index 为输入框输入内容
        :return:None
        """
        self.input_text(self.yomi_tip_input, index)

    def get_number(self):
        """
        获取yomi字数

        :return:获取元素
        """
        return self.find_element_o(self.yomi_number_text)

    def get_carried_out_title(self):
        """
        获取yomi执行标题

        :return:获取元素
        """
        return self.find_element_o(self.yomi_carried_out_title_text)

    def click_add_skill(self, index=1):
        """
        点击技能添加

        :return:None
        """
        self.yomi_add_skill_btn = (By.XPATH, Yomi.skills_added.format(index))
        self.click_element(self.yomi_add_skill_btn)

    def click_added_frame(self, index=1):
        """
        点击技能添加

        :return:None
        """
        self.skills_added_frame_icon = (By.XPATH, Yomi.skills_added_frame.format(index))
        self.click_element(self.skills_added_frame_icon)

    def get_added_name(self, index=1):
        """
        获取技能添加名称

        :return:获取元素
        """
        self.skills_added_name_text = (By.XPATH, Yomi.skills_added_name.format(index))
        return self.find_element_o(self.skills_added_name_text)

    def click_added_close(self, index=1):
        """
        点击技能关闭按钮

        :return:None
        """
        self.skills_added_close_icon = (By.XPATH, Yomi.skills_added_close.format(index))
        self.click_element(self.skills_added_close_icon)

    def get_added_control(self, index=1):
        """
        获取技能详细内容

        :return:获取元素
        """
        self.skills_added_control_text = (By.XPATH, Yomi.skills_added_control.format(index))
        return self.find_element_o(self.skills_added_control_text)

    def click_save(self):
        """
        点击保存按钮

        :return:None
        """
        self.click_element(self.yomi_save_btn)

    def click_cancel(self):
        """
        点击取消按钮

        :return:None
        """
        self.click_element(self.yomi_cancel_btn)

    def is_display_yomi_details(self):
        """
        查看是否进入语音训练详情页

        :return:
        """
        return self.is_display(self.yomi_add_skill_title_text)
